package com.zoe.onelink.plugin.check.report;

import com.zoe.onelink.plugin.check.exception.PropertyCheckException;
import com.zoe.onelink.plugin.check.model.PropertyCheckResult;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-09-20
 */
@Slf4j
public class PropertyCheckerConsoleReporter implements PropertyCheckerReporter {

    @Override
    public void report(List<PropertyCheckResult<?>> sortedPropertyCheckResults) {
        for (PropertyCheckResult<?> checkResult : sortedPropertyCheckResults) {
            String propertyKey = checkResult.getPropKey();
            Object propValue = checkResult.getPropValue();
            String message = checkResult.getMessage();
            PropertyCheckResult.Level level = checkResult.getLevel();
            // 调试级别
            if (level.getVal() <= PropertyCheckResult.Level.DEBUG.getVal()) {
                log.debug("[环境检查模块] [{}] [{}={}] {}", level.getDesc(), propertyKey, propValue, message);
                // 普通级别
            } else if (level.getVal() == PropertyCheckResult.Level.NORMAL.getVal()) {
                log.info("[环境检查模块] [{}] [{}={}] {}", level.getDesc(), propertyKey, propValue, message);
                // 危险级别
            } else if (level.getVal() == PropertyCheckResult.Level.DANGER.getVal()) {
                log.warn("[环境检查模块] [{}] [{}={}] {}", level.getDesc(), propertyKey, propValue, message);
                // 严重级别
            } else if (level.getVal() >= PropertyCheckResult.Level.SEVERITY.getVal()) {
                throw new PropertyCheckException(checkResult);
            }
        }
    }

}
